import rolePageApi from '@/api/role/rolePageApi'
import { OptionProps } from '@douyinfe/semi-ui/lib/es/select'
import { useEffect, useState } from 'react'

// 获取所有角色列表
export default function useEffectRolePage(noLoading: boolean) {
  const [roleList, setRoleList] = useState<OptionProps[]>([])

  useEffect(() => {
    if (!noLoading) {
      rolePageApi({
        pageSize: -1,
        defaultOrderFlag: true,
      }).then(({ data }) => {
        setRoleList(
          data.data.records.map((item) => ({
            label: item.name,
            value: item.id,
          })) as OptionProps[]
        )
      })
    }
  }, [noLoading])

  return { roleList }
}
